home *** CD-ROM | disk | FTP | other *** search
- Path: in2.uu.net!telepath!usenet
- From: jdavis@inthenet.com (Papillon)
- Newsgroups: comp.lang.c
- Subject: Re: division problem
- Date: Wed, 21 Feb 1996 15:36:23 GMT
- Organization: inthenet.com
- Message-ID: <4gfdut$8n5@zoom2.telepath.com>
- References: <31097D77.11AA@rain.org> <4eirpq$8ut@airdmhor.gen.nz>
- NNTP-Posting-Host: slip1.inthenet.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- gumboot@airdmhor.gen.nz (Simon Hosie) wrote:
-
- >tpaul:
- >> Can anyone show me why this does not work? I am a beginner.
-
- > 1> #include <stdio.h>
-
- > 3> main ()
- > 4> {
- > 5> int fahrenheit, celsius;
-
- > 7> printf("Fahrenheit temperature =?";
- > 8> scanf("%d",fahrenheit);
- > 9> celsius = 5/9*(fahrenheit-32);
- >10> printf("Fahrenheit = %d, Celsius = %d", fahrenheit, celsius;
- >11> }
-
- > I don't know if the guy I told off answered this (I just looked at his
- >answer and got upset). Firstly you don't have any closing brackets on your
- >printf()'s, secondly..
-
- > I can't quite remember how C chooses the types to use, I think it's the
- >first thing after the '='.. anyway, it's doing integer math. The first
- >thing it does is divide 5 by 9, that gives 0 (the remainder is thrown away)
- >then it multiplies (fahrenheight - 32) by 0.
-
- > The solution is to do your multiplies first. The solution is _not_ to use
- >floating point.
-
- Also, the scanf() function should read: scanf("%d", &fahrenheit) in
- order to read in the value and pass it.
-
-